?matrix
install.packages("dplyr")
install.packages(c("cowplot", "diagis", "extrafont", "hrbrthemes"))
install.packages("rtweet")
library(rtweet)
likes <- get_favorites("andyguess", n = 3000)
likes
View(likes)
install.packages("wordcloud2")
library(wordcloud2)
wordcloud2(likes$screen_name)
likes$screen_name
library(tidyverse)
sns <- likes %>% group_by(screen_name) %>% summarize(freq = n())
sns
wordcloud2(sns)
?hrbrthemes
??hrbrthemes
hrbrthemes::loadonts
hrbrthemes::loadfonts
extrafont::loadfonts
pdfFonts()
names(pdfFonts())
?extrafont
extrafont::fonts()
extrafont::fonts
fonttable()
extrafont()
library(extrafont)
fonttable()
pdfFonts()
library(hrbrthemes)
wordcloud2(sns, fontFamily = "Roboto")
wordcloud2(sns, fontFamily = "Roboto Condensed")
wordcloud2(sns, fontFamily = "Helvetica")
wordcloud2(sns, fontFamily = "Helvetica")
wordcloud2(sns)
likes$text
head(likes$text)
write_csv(likes, "~/Documents/mylikes_march2020.csv")
save(likes, file = "~/Documents/mylikes_march2020.RData")
likes %>% select(text) %>% str_detect("graph")
likes %>% select(text)
?str_detect
likes %>% select(text) %>% str_which("graph")
likes %>% select(text) %>% str_subset("graph")
likes %>% select(text)
likes$text %>% str_subset("graph")
install.packages("extrafontdb")
devtools::install_github("hrbrmstr/hrbrthemes", force = TRUE)
install.packages("devtools")
devtools::install_github("hrbrmstr/hrbrthemes", force = TRUE)
hrbrthemes::import_roboto_condensed()
extrafont::loadfonts()
library(hrbrthemes)
library(ggplot2)
load("/Users/aguess/Dropbox (Princeton)/SMaPP_US2016B/fake_news/data/fb_user_shares.RData")
table(user_feed$respondent_id)
class(user_feed)
user_feed
head(user_feed)
load("/Users/aguess/Dropbox (Princeton)/SMaPP_US2016B/fake_news/data/fb_user_shares_clean.RData")
head(user_feed)
x<-1:4
n<-length(x)
mean(x)
10/4
var(x)
sum(x)
sum(x)/n
mean(x)
sum((x-mean(x))^2)/n
sum((x-mean(x))^2)/(n-1)
?var
swiss
?swiss
pairs(swiss, panel = panel.smooth, main = "swiss data",
col = 3 + (swiss$Catholic > 50))
summary(lm(Fertility ~ . , data = swiss))
?pairs
?tidyverse::mutate_all
??mutate_all
iris
iris <- as_tibble(iris)
library(tidyverse)
iris <- as_tibble(iris)
iris
scale2 <- function(x, na.rm = FALSE) (x - mean(x, na.rm = na.rm)) / sd(x, na.rm)
starwars
starwars %>% mutate_at(c("height", "mass"), scale2)
starwars %>% mutate_at(c("height", "mass"), scale2, na.rm = TRUE)
starwars %>% mutate_at(c("height", "mass"), ~ scale2(., na.rm = TRUE))
iris %>% mutate_at(vars(matches("Sepal")), log)
starwars
starwars %>% mutate_if(is.numeric, scale2, na.rm = TRUE)
iris
iris %>% mutate_if(is.factor, as.character)
i
iris %>% mutate_if(is.factor, as.character)
iris %>% mutate_at(vars(Sepal.Length), log)
iris %>% mutate_if(is.numeric, list(scale2, log))
`%>%` = magrittr::`%>%`
`%<>%` = function (x, y) {
message("%<>% was called")
y
}
x = 1
magrittr::`%>%`
x %<>% `+`(2)
`+`(2)
`+`(2)
x %<>% `+`(2) %>% `*`(2); x
Data <- data.frame(
Name_Bad = sample(1:10),
Name_Guud = sample(1:10)
)
Data
colnames(Data)
colnames(Data) %<>%
stringr::str_remove_all("_Bad") %>%
stringr::str_replace_all("Guud", "Good")
library(dplyr)
colnames(Data) %<>%
stringr::str_remove_all("_Bad") %>%
stringr::str_replace_all("Guud", "Good")
Data
Data <- data.frame(
Name_Bad = sample(1:10),
Name_Guud = sample(1:10)
)
colnames(Data) %<>%
stringr::str_remove_all("_Bad")
library(stringr)
colnames(Data) %<>%
str_remove_all("_Bad")
# Error: could not find function "%<>%"
rm(Data)
library(tidyverse)
library(tidyverse)
letters
tibble(letters[1:3])
test <- tibble(letters[1:3])
test
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %<>% ungroup()
test %<>% mutate(n = 1:3) %>% ungroup()
test
test <- tibble(letters[1:3])
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% ungroup()
test %<>% mutate(n = 1:3) %T>% dput()
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% print()
test <- tibble(letters[1:3])
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% print()
test
test <- tibble(letters[1:3])
test
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% print()
test
test <- tibble(abc = letters[1:3])
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% print()
mtcars
mtcars %<>% transform(cyl = cyl * 2)
library(dplyr)
test <- tibble(abc = letters[1:3])
test %<>% mutate(n = 1:3)
detach(package:dplyr, unload = TRUE)
install.packages(c("dplyr", "purrr", "tibble"))
library(tidyverse)
test <- tibble(abc = letters[1:3])
test %<>% mutate(n = 1:3)
test %<>% mutate(n = 1:3) %>% print()
test
test %<>% mutate(n = 1:3)
test
install.packages("cobalt")
library(cobalt)
d<-read.csv("/Users/aguess/Downloads/covid_deathrates.csv")
d
head(d)
library(tidyverse)
d <- read_csv("/Users/aguess/Downloads/covid_deathrates.csv")
head(d)
d
d %>% arrange(desc(deaths))
d %>% arrange(desc(deathrate))
d %>% arrange(desc(deaths))
d %>% arrange(desc(deathrate))
d %>% arrange(desc(deaths))
d %>% arrange(desc(deaths))
library(tidyverse)
library(rtweet)
andy <- lookup_users("andyguess")
andy
users_data(andy)
tweets <- get_timeline("andyguess", n = 3200)
tail(tweets)
head(tweets$text)
tweets$text %>% str_subset("mirman")
tweets$text %>% str_subset("mirman")
?str_subset
tweets$text %>% str_detect("mirman")
tweets$text %>% str_which("mirman")
tweets$text %>% str_which("eugene")
tweets$text %>% str_which("Eugene")
tweets[1960,]
tweets[1960,]$text
tweets[1960,]
tweets[1960,1:5]
names(tweets)
View(tweets[1960,])
tweets[1960,1:5]
tweets[1960,1:5]$text
tweets[1960,]$text
tweets$text %>% str_which("Eugene")
library(tidyverse)
library(haven)
library(arm)
install.packages("arm")
library(arm)
setwd("/Users/d31713r/Dropbox/GuessNyhanReifler/DART0023/PNAS/post_accept/replication files/US data/")
setwd("~/Dropbox/GuessNyhanReifler/DART0023/PNAS/post_accept/replication files/US data/")
setwd("~/Dropbox (Princeton)/GuessNyhanReifler/DART0023/PNAS/post_accept/replication files/US data/")
dat <- read_dta("US_data_clean_w1_headline.DTA")
mod3 <- lmer(accuracy ~ tips + (tips | dv), data = dat) # random intercept + random slope - all headlines
ggdat1 <- ranef(mod3)$dv %>% dplyr::select(1) %>% rownames_to_column() %>% rename(estimate = "(Intercept)",
headline = rowname) %>% mutate(type = "intercept")
ggdat2 <- ranef(mod3)$dv %>% dplyr::select(2) %>% rownames_to_column() %>% rename(estimate = tips,
headline = rowname) %>% mutate(type = "slope")
ggdat <- bind_rows(ggdat1, ggdat2)
ggdat$SE <- c(se.ranef(mod3)$dv[,1], se.ranef(mod3)$dv[,2])
ggdat$pro <- rep(rep(c(rep("D", 4), rep("R", 4)), 2), 2)
ggdat$source <- rep(c(rep(c(rep("Hyper", 2), rep("False", 2)), 2), rep(c(rep("Mainstream (low prominence)", 2), rep("Mainstream", 2)), 2)), 2)
ggdat$headline <- paste0(ggdat$source, " pro-", ggdat$pro)
ggdat$headline <- paste0(ggdat$headline, " ", rep(1:2, nrow(ggdat)/2))
library(cowplot)
g <- ggplot(filter(ggdat, type == "intercept"), aes(headline, estimate)) +
geom_hline(yintercept = 0, color = gray(1/2), lty = 2) +
geom_pointrange(aes(y = estimate,
ymin = estimate - SE*1.96,
ymax = estimate + SE*1.96)) +
xlab("") + ylab("") + ggtitle("Baseline perceived accuracy") + ylim(-.7, .7) +
coord_flip()
gg_intercept <- g + theme_minimal()
g <- ggplot(filter(ggdat, type == "slope"), aes(headline, estimate)) +
geom_hline(yintercept = 0, color = gray(1/2), lty = 2) +
geom_pointrange(aes(y = estimate,
ymin = estimate - SE*1.96,
ymax = estimate + SE*1.96)) +
xlab("") + ylab("") + ggtitle("Headline-specific tips effect") + ylim(-.7, .7) +
coord_flip()
gg_slope <- g + theme_minimal() + theme(axis.text.y = element_blank())
ggboth <- plot_grid(gg_intercept, gg_slope, rel_widths = c(1.4, 1))
ggboth
ggboth
